<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreatePlanTaskRelationTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('plan_task_relation', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '记录表']);
        $table
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('task_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '任务id'])
            ->addColumn('plan_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '排期id'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addColumn('created', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addIndex(['task_id'], ['type' => 'normal', 'name' => 'idx_task_id'])
            ->addIndex(['plan_id'], ['type' => 'normal', 'name' => 'idx_plan_id'])
            ->create();
    }

    public function down()
    {
        $this->table('plan_task_relation')->drop()->save();
    }
}
